//首页分类模块
'use strict';
import {
    StyleSheet,
    TouchableOpacity,
    Text,
    AlertIOS,
    Image,
    View,
} from 'react-native';
import React from 'react';
import URL from '../config/server';
import {Utils} from '../config/utils';
import {Key} from '../config/key';

export default class Category extends React.Component {

    toCategory(target, level) {
        let that = this;
        const STOCK_LEVEL = URL.checkright+'stock/'+level;
        const DAILY_LEVEL = URL.checkright + 'daily/0';
        if(level>0){
            Utils.transport1(STOCK_LEVEL, '', function (data) {
                if(data ==-2){
                    AlertIOS.alert(
                        '您的权限不够',
                        '管理员关闭升级功能,请联系客服.'
                    )

                }else if(data==-1){
                    AlertIOS.alert(
                        '您的权限不够',
                        '请您升级权限, 或等到休市之后再来访问.',
                        [
                            {
                                text: '去升级', onPress: () => {
                                if (Key.username == '') {
                                    that.props.navigator.push({
                                        id: 'Register'
                                    })
                                } else {
                                    that.props.navigator.push({
                                        id: 'MyRule'
                                    })
                                }
                            }
                            },
                            {text: '取消'}
                        ]
                    )
                }else{
                    that.props.navigator.push({
                        id: target,
                        message: {
                            ncType:level,
                            showDate: null
                        }
                    })
                }
            });
        }else{
            Utils.transport(DAILY_LEVEL, '', function (data) {
                if(data){
                    that.props.navigator.push({
                        id: target,
                        message: level
                    })
                }else{
                    AlertIOS.alert(
                        '您的权限不够',
                        '请您升级权限, 或等到休市之后再来访问.',
                        [
                            {
                                text: '去升级', onPress: () => {
                                if (Key.username == '') {
                                    that.props.navigator.push({
                                        id: 'Register'
                                    })
                                } else {
                                    that.props.navigator.push({
                                        id: 'MyRule'
                                    })
                                }
                            }
                            },
                            {text: '取消'}
                        ]
                    )
                }
            });
        }
    }

    render() {
        return (
            <View style={[styles.boxs,{borderBottomWidth:4,borderColor:'#f5f5f9'}]}>
                <View style={styles.box}>
                    <TouchableOpacity onPress={this.toCategory.bind(this,'Mrzt',0)} style={styles.boxItem}>
                        <Image source={require('../image/mr.png')} style={styles.boxImg}/>
                        <Text style={styles.boxText}>每日涨停</Text>
                    </TouchableOpacity>
                    <TouchableOpacity onPress={this.toCategory.bind(this,'Nc',1)} style={styles.boxItem}>
                        <Image source={require('../image/cj.png')} style={styles.boxImg}/>
                        <Text style={styles.boxText}>初级内参</Text>
                    </TouchableOpacity>
                    <TouchableOpacity onPress={this.toCategory.bind(this,'Nc',2)} style={styles.boxItem}>
                        <Image source={require('../image/gr.png')} style={styles.boxImg}/>
                        <Text style={styles.boxText}>个人内参</Text>
                    </TouchableOpacity>
                </View>
                <View style={styles.box}>
                    <TouchableOpacity onPress={this.toCategory.bind(this,'Nc',3)} style={styles.boxItem}>
                        <Image source={require('../image/bj.png')} style={styles.boxImg}/>
                        <Text style={styles.boxText}>白金内参</Text>
                    </TouchableOpacity>
                    <TouchableOpacity onPress={this.toCategory.bind(this,'Nc',4)} style={styles.boxItem}>
                        <Image source={require('../image/sr.png')} style={styles.boxImg}/>
                        <Text style={styles.boxText}>私募内参</Text>
                    </TouchableOpacity>
                    <TouchableOpacity onPress={this.toCategory.bind(this,'Nc',5)} style={styles.boxItem}>
                        <Image source={require('../image/sm.png')} style={styles.boxImg}/>
                        <Text style={styles.boxText}>神秘内参</Text>
                    </TouchableOpacity>
                </View>
            </View>
        )

    }
}
// 组件样式
const styles = StyleSheet.create({
    boxs: {
        marginTop: -2
    },
    box: {
        flexDirection: 'row',
        justifyContent: 'center',
        paddingTop: 10,
        paddingBottom: 5,
        paddingLeft: 5,
        paddingRight: 5,
        backgroundColor: '#ffffff'
    },
    boxImg: {
        width: 45,
        height: 45,
        marginBottom: 10
    },
    boxItem: {
        flex: 1,
        flexDirection: 'column',
        justifyContent: 'center',
        alignItems: 'center',
        padding: 2
    },
    boxText: {
        color: '#333333',
        fontSize: 12
    }

});
